﻿using System.Collections;
using System.Collections.Generic;
using Game;
using UnityEngine;
using ZYLFramework.Manage;

public class SceneVariants{
    public static LevelManager levelManager;
    public static GameManager gameManager;
    public static DamageManager DamageManager;
    public static UIManage UIManage;
    public static EventManage EventManage;
    public static TimelineManager TimelineManager;

    //创建一个地图
    public static MapInfo RandomMap(int mapWidth, int mapHeight)
    {
        GridInfo gridInfo = DesignerTables.MapInfo.MapType["Grassland"];
        GridInfo[,] mGrids = new GridInfo[mapWidth, mapHeight];
        for (var i = 0; i < mapWidth; i++){
            for (var j = 0; j < mapHeight; j++){
                mGrids[i, j] = gridInfo;
            }
        }
        return new MapInfo(mGrids, Vector2.one);
    }
    
    public static UIManage GetUIManage()
    {
        if (UIManage == null)
        {
            UIManage = GameObject.Find("GameManager").GetComponent<UIManage>();
        }
        return UIManage;
    }

    public static LevelManager GetLevelManager()
    {
        if (levelManager == null)
        {
            levelManager = GameObject.Find("GameManager").GetComponent<LevelManager>();
        }
        return levelManager;
    }
    
    public static GameManager GetGameManager()
    {
        if (gameManager == null)
        {
            gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
        }
        return gameManager;
    }
    
    public static DamageManager GetDamageManager()
    {
        if (DamageManager == null)
        {
            DamageManager = GameObject.Find("GameManager").GetComponent<DamageManager>();
        }
        return DamageManager;
    }
    
    public static EventManage GetEventManage()
    {
        if (EventManage == null)
        {
            EventManage = GameObject.Find("GameManager").GetComponent<EventManage>();
        }
        return EventManage;
    }
    
    public static TimelineManager GetTimelineManager()
    {
        if (TimelineManager == null)
        {
            TimelineManager = GameObject.Find("GameManager").GetComponent<TimelineManager>();
        }
        return TimelineManager;
    }
    
    //加载一个关卡
    public static void LoadLevel(int levelId){
        GetLevelManager().LoadLevel(levelId);
    } 
        
    //结束某个阵营的回合
    public static void OverCompRound(){
        GetLevelManager().SetRoundState(RoundState.Over);
    } 
    
    //检查是否超过关卡边界
    public static bool CheckGridInPosition(Vector2 pos){
        return GetGameManager().CheckGridInPosition(pos);
    } 
    
    ///<summary>
    ///添加一个damageInfo
    ///<param name="attacker">攻击者，可以为null</param>
    ///<param name="target">挨打对象</param>
    ///<param name="damage">基础伤害值</param>
    ///<param name="criticalRate">暴击率，0-1</param>
    ///<param name="tags">伤害信息类型</param>
    ///</summary>
    public static void CreateDamage(GameObject attacker, GameObject target, Damage damage, float criticalRate, DamageInfoTag[] tags){
        GetDamageManager().DoDamage(attacker, target, damage, criticalRate, tags);
    }

    /// <summary>
    /// 清除一个棋子
    /// </summary>
    /// <param name="Pawn"></param>
    public static void ClearPawn(GameObject Pawn){
        GetLevelManager().ClearPawn(Pawn);
        GetLevelManager().RecyclePawn(Pawn);
    }
    
    /// <summary>
    /// 注册一个通知事件
    /// </summary>
    public static void RegisterMessageEvent(EventEnum eventEnum,EventDelegate func){
        GetEventManage().Register(eventEnum,func);
    }
    
    /// <summary>
    /// 触发一个通知事件
    /// </summary>
    public static void NotifyMessageEvent(EventEnum eventEnum,params object[] obj){
        GetEventManage().Notify(eventEnum,obj);
    }
    
    /// <summary>
    /// 获取UI相机
    /// </summary>
    public static Camera GetUICamera(){
        return GetGameManager().UICamera.GetComponent<Camera>();
    }
    
    ///<summary>
    ///添加一个timeline
    ///<param name="timelineModel">要添加的timeline的model</param>
    ///<param name="caster">timeline的负责人</param>
    ///<param name="source">添加的源数据，比如技能就是skillObj</param>
    ///</summary>
    public static void CreateTimeline(TimelineModel timelineModel, GameObject caster, object source){
        GetTimelineManager().AddTimeline(timelineModel, caster, source);
    }

    ///<summary>
    ///添加一个timeline
    ///<param name="timelineObj">要添加的timeline</param>
    ///</summary>
    public static void CreateTimeline(TimelineObj timeline){
        GetTimelineManager().AddTimeline(timeline);
    }
}